// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
var CreatorHelper = require('CreatorHelper')

cc.Class({
    extends: cc.Component,

    properties: {
        uid: 0,
        head: cc.Sprite,
        username: cc.Label,
        balance: cc.Label,
        bet: cc.Label,
        realyStatus: cc.Label
    },

    /**
     * [init description]
     * @param  {[type]} data
     * uid, head, username, balance, bet, realyStatus, pos
     * @return {[type]}      [description]
     */
    init (data) {
        var defaultPath = 'images/smallimages/table/people/'
        var number = data.pos+1
        var figureHeadPath = defaultPath + number

        this.uid = data.uid
        this.node.uid = data.uid
        this.username.string = data.username
        this.balance.string = data.balance + ' '
        this.bet.string = data.bet + ' '

        if (data.realyStatus === 0) {
            this.realyStatus.string = '未准备'
        } else if (data.realyStatus === 1) {
            this.realyStatus.string = '已准备'
        } else if (data.realyStatus === 2) {
            this.realyStatus.string = '房主'
        } else if (data.realyStatus === 3) {
            this.realyStatus.string = ' '
        }

        CreatorHelper.changeSpriteFrame(this.head, figureHeadPath)
    }
});
